-- card: 12440 from stack: in.5 -- bmap block id: 12671 -- flags: 0000 -- background id: 3858 -- name: DiskIsRemovable ----- HyperTalk script ----- on hideObjects hide cd btn "Try It!" end hideObjects on showObjects show cd btn "Try It!" end showObjects -- part 1 (button) -- low flags: 00 -- high flags: A002 -- rect: left=82 top=185 right=219 bottom=175 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 8192 -- line height: 16 -- part name: Try it! ----- HyperTalk script ----- on mouseUp global errGlobal put VolumePath() into diskToCheck if diskToCheck = "" then exit mouseUp put DiskIsRemovable(diskToCheck,"noDialog:errGlobal") into remvState if errGlobal ≠ empty then answer "Error:" && errGlobal put empty into errGlobal else if remvState = "True" then put "is" into verb else put "is not" into verb answer "The disk “" & diskToCheck & "”" && verb && "removable." end if end mouseUp -- part contents for background part 38 ----- text ----- 9/50 -- part contents for background part 20 ----- text ----- An XFCN which reports whether or not the specified volume is removable. Calling syntax : DiskIsRemovable(diskname, <"noDialog:"errorGlobal>) -- part contents for background part 42 ----- text ----- { DiskIsRemovable(VolName «,“noDialog:”errorGlobal»)} { XCMD to test for a removable disk} {} { brought to you by: Anup Murarka Eric Carlson } { ALINK: SKEPTIC ALINK: cyNic } { CIS: 76004,3356 } {} { We are part of the Support Tools Development Group, } { Apple Computer, Inc. } {} { please DO NOT contack Mac DTS for support of this code! } {} { please DO contact the authors for support of this code! } {} { Send comments, bug reports, requests to any of the above } { E-mail addresses or to:} {} { (one of us) } { Apple Computer, Inc. } { 900 E. Hamilton, Ave. } { Campbell, CA 95008 } { M/S 72-L } {} { Copyright: © 1989, 1990 by Apple Computer, Inc., all rights reserved. } {} { written by Eric Carlson } { AppleLink: cyNic } { modification history } { Date Initials Comments } { ---- ------ ------------------------------------------------------ } { 1/20/90 ec first written } { 4/3/90 ec fixed bug for partitioned disks returning $48 } { 6/2/90 ec commented code further } {} {} unit DiskIsRemovable; interface uses HyperXCmd; procedure MAIN (paramPtr: XCmdPtr); implementation procedure reportToUser (paramPtr: XCmdPtr; msgStr: str255); {} { report something back to the user. } { the last parameter (optional) to an external may contain } { "noDialog" or "noDialog:GlobalName". GlobalName is the name } { of a HyperTalk global variable into which error messages will be } { placed. we've decided to use this approach to avoid confusing } { an error message with a valid result being returned from an XFCN. } {} var tempStr: str255; begin {check the last param to see if the user requested that} { we suppress the error dialog } ZeroToPas(paramPtr, paramPtr^.params[paramPtr^.paramCount]^, tempStr); UprString(tempStr, true); if pos('NODIALOG', tempStr) = 0 then { no special error handling specified, throw up a dialog and return the error message } begin SendCardMessage(paramPtr, concat('answer "', msgStr, '"')); paramPtr^.returnValue := PasToZero(paramPtr, msgStr); end else if (pos(':', tempStr) > 0) then { requested global AND noDialog so we fill in the global and return empty } begin tempStr := copy(tempStr, pos(':', tempStr) + 1, length(tempStr)); { get the name of the HC global to fill } SetGlobal(paramPtr, tempStr, PasToZero(paramPtr, msgStr)); { and fill it } paramPtr^.returnValue := PasToZero(paramPtr, '');{ return empty } end else { requested noDialog only so we return the error condition as the result } paramPtr^.returnValue := PasToZero(paramPtr, msgStr); end;{ procedure } function AskedForHelp (paramPtr: XCmdPtr; syntaxMsg: Str255; copyrightMsg: Str255): boolean; {check to see if the user sent a '?' or a '!' as } { the only parameter. if so we will respond with } { the calling syntax or the copyright/version info } { for this external } {} var firstStr: str255; begin askedForHelp := false; if paramPtr^.paramCount = 1 then begin ZeroToPas(paramPtr, paramPtr^.params[1]^, firstStr); { what is the first param? } if firstStr = '?' then begin reportToUser(paramPtr, syntaxMsg); askedForHelp := true end{ asked for help } else if firstStr = '!' then begin reportToUser(paramPtr, copyRightMsg); askedForHelp := true end;{ asked for copyright info } end;{ one parameter passed } end;{ function } function NumberToString (paramPtr: XCmdPtr; num: LONGINT): Str255; { use the toolbox call rather than HC's } var tempStr: str255; begin NumToString(num, tempStr); NumberToString := tempStr; end; procedure ReportVolError (paramPtr: XCmdPtr; errorNum: integer); var errMsg, tempName: str255; begin sysbeep(40); case errorNum of{ what caused the problem? } bdNamErr: errMsg := 'Bad volume name.'; extFSErr: errMsg := 'External file system.'; ioErr: errMsg := 'I/O Error.'; nsDrvErr: errMsg := 'No such drive.'; nsvErr: errMsg := 'No such volume.'; paramErr: errMsg := 'No default volume.'; otherwise errMsg := concat('unexpected error #', NumberToString(paramPtr, errorNum)); end;{ case } errMsg := concat('Sorry, ', errMsg); reportToUser(paramPtr, errMsg); { return the error message } end;{ function } function DriveRemovable (aDQEPtr: DrvQElPtr): boolean; { the long proceeding each element in the drive que contains a flag in } { byte 1 which = 0 if no disk is in the drive, 1 or 2 if a disk is in the } { drive, and 8 if a non removable disk is in the drive, or $48 if the } { disk is non removable but the 'driver wants a call' (IM IV-181) } { 11:42 AM 1/10/90 ec } var flagsPtr: ^longint; tempLong: longint; begin {subtract 4 from the DrvQE1Ptr to grab the long there } flagsPtr := pointer(ord4(aDQEPtr) - 4); tempLong := BAND(BSR(flagsPtr^, 16), $FF); DriveRemovable := (tempLong <> 8) and (tempLong <> $48); end; function DriveNumToQueElement (driveNum: integer): DrvQElPtr; { given a drive number, return a drive que pointer for that drive } { 12:32 PM 3/1/90 ec } var aQueElement: DrvQElPtr; headPtr: QHdrPtr; begin headPtr := GetDrvQHdr; { grab the drive que header } if headPtr <> nil then begin aQueElement := DrvQElPtr(headPtr^.qHead); while (aQueElement^.dQDrive <> driveNum) and (aQueElement <> nil) do aQueElement := DrvQElPtr(aQueElement^.qLink); DriveNumToQueElement := aQueElement; end else DriveNumToQueElement := nil; end; function ValidVolumeName (volumeName: str255): str255; { a volume name must have one (and only one) colon in it, as } { the last character } begin if pos(':', volumeName) = 0 then validVolumeName := concat(volumeName, ':') else validVolumeName := copy(volumeName, 1, pos(':', volumeName)); end; procedure DiskIsRemovable (paramPtr: XCmdPtr); var volToCheck, tempVar: str255; PB: HParamBlockRec; errorCode: OSErr; begin if AskedForHelp(paramPtr, 'DiskIsRemovable(diskName, «“noDialog:”errorGlobal»)', '© 1990 Apple Computer, Inc., v1.0 by 1990 Eric Carlson') then exit(DiskIsRemovable); if paramPtr^.paramCount = 0 then begin ReportToUser(paramPtr, 'Disk name expected.'); exit(DiskIsRemovable); end else ZeroToPas(paramPtr, paramPtr^.Params[1]^, volToCheck); volToCheck := validVolumeName(volToCheck);{ make sure the volume name is correct } { initialize parameter block. Since volToCheck is a full pathname, no other field is needed} zeroBytes(paramPtr, @PB, sizeOf(PB)); PB.ioNamePtr := @volToCheck;{ use the name passed } PB.ioVolIndex := -1;{ and ONLY the name } errorCode := PBHGetVInfo(@PB, false); if errorCode <> noErr then begin ReportVolError(paramPtr, errorCode); exit(DiskIsRemovable); end; if DriveRemovable(DriveNumToQueElement(PB.ioVDrvInfo)) then tempVar := 'True' else tempVar := 'False'; ParamPtr^.returnValue := PasToZero(paramPtr, tempVar); end;{ procedure DiskIsRemovable} procedure MAIN (paramPtr: XCmdPtr); begin DiskIsRemovable(paramPtr); end; end.{ unit DiskIsRemovable}